package com.webank.wedatasphere.qualitis.controller.thymeleaf;

import com.webank.wedatasphere.qualitis.question.controller.vo.MyOrderDetailVo;
import com.webank.wedatasphere.qualitis.question.entity.Order;
import com.webank.wedatasphere.qualitis.question.service.MyOrderService;
import com.webank.wedatasphere.qualitis.question.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;


@RestController
@RequestMapping("/question")
public class QuestionController {

    @Resource
    private OrderService orderService;

    @Resource
    private MyOrderService myOrderService;

    /**
     * 数据源
     * @return
     */
    @RequestMapping(value = {"/list"}, method = RequestMethod.GET)
    public ModelAndView question() {
        return new ModelAndView("layui-admin/question/list");
    }

    @RequestMapping(value = {"/order/list"}, method = RequestMethod.GET)
    public ModelAndView orderList() {
        return new ModelAndView("layui-admin/question/order/list");
    }

    @RequestMapping(value = {"/myorder/list"}, method = RequestMethod.GET)
    public ModelAndView myorderList() {
        return new ModelAndView("layui-admin/question/myorder/list");
    }

    @RequestMapping(value = {"/order/detail"}, method = RequestMethod.GET)
    public ModelAndView orderDetail(@RequestParam Long id, @RequestParam(required = false) String method) {
        MyOrderDetailVo orderDetail = myOrderService.getDetailVo(id);
        ModelAndView view = new ModelAndView("layui-admin/question/order/detail");
        view.addObject("orderDetail", orderDetail);

        view.addObject("backUrl", "/qa/question/order/list");
        view.addObject("method", method);
        view.addObject("readonly", true);
        if ("edit".equals(method)) {
            view.addObject("readonly", false);
        }

        return view;
    }

    @RequestMapping(value = {"/myorder/detail"}, method = RequestMethod.GET)
    public ModelAndView myorderDetail(@RequestParam Long id, @RequestParam(required = false) String method) {
//        Order order = orderService.get(id);
        MyOrderDetailVo orderDetail = myOrderService.getDetailVo(id);
        ModelAndView view = new ModelAndView("layui-admin/question/order/detail");
        view.addObject("orderDetail", orderDetail);

        view.addObject("backUrl", "/qa/question/myorder/list");
        view.addObject("method", method);
        view.addObject("readonly", true);
        if ("edit".equals(method)) {
            view.addObject("readonly", false);
        }

        return view;
    }


}
